/*
 * 文件名：CarInMemberResponceHandler.java	 
 * 时     间：下午8:57:03
 * 作     者：lyf       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.message.handler.impl;

import java.util.List;

import org.springframework.context.ApplicationContext;

import com.cz073586.tools.util.JsonUtil;
import com.cz073586.tools.util.Log4jUtil;
import com.cz073586.tools.util.Tools;
import com.local.entity.vo.ParkwellPayBillVo;
import com.local.model.CarLockInfo;
import com.local.model.CarLockInfoExample;
import com.local.model.CarParkOut;
import com.local.service.face.CarLockInfoService;
import com.local.service.face.ParkwellCarOutService;
import com.message.entity.TransDataVo;
import com.message.handler.face.ResponceHandler;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.utils.I18nUtil;

/**
 * 类描述: 新增特殊车辆接口
 * 
 * @ClassName: CarInMemberResponceHandler
 * @author zhangw
 * @date 2015年10月12日 下午8:57:03
 */
public class CarLockInfoResponceHandler implements ResponceHandler
{
	private Log4jUtil log = Log4jUtil
			.getLog4j(CarLockInfoResponceHandler.class);
	
	@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
	@Override
	public TransDataVo resoponse(ApplicationContext srpingApp,
			TransDataVo transData)
	{
		TransDataVo result = new TransDataVo<CarLockInfo>();
		if (!Tools.isEmpty(transData.getData()))
		{
			
			try
			{
				String json = JsonUtil.getJsonString(transData.getData());
				List<CarLockInfo> cloudData = JsonUtil.fromJson(json,
						List.class, CarLockInfo.class);
				CarLockInfoService serverice = srpingApp
						.getBean(CarLockInfoService.class);
				for(CarLockInfo ss:cloudData){
					CarLockInfoExample condtion=new CarLockInfoExample();
					condtion.or().andParkCodeEqualTo(ss.getParkCode()).andCarNoEqualTo(ss.getCarNo());
					serverice.deleteByCondition(condtion);
				}
				for(CarLockInfo ss:cloudData){
					ss.setUuid(null);
					serverice.saveOrUpdateCarLockInfo(ss);
					/*if (XltCloudConfigManager.instance().isOpen())
					{
						serverice.jdbcCall(ss.getCarNo(), ss.getCarLock(), !Tools.isEmpty(ss.getRemark())?ss.getRemark():null);
					}*/
					if(!Tools.isEmpty(ss.getCarLock())&&ss.getCarLock()==0){
						ParkwellCarOutService carParkOutService = srpingApp
								.getBean(ParkwellCarOutService.class);
						//查询待出场的车牌
						CarParkOut cc=serverice.QueryByCarNo(ss.getCarNo());
						if(!Tools.isEmpty(cc)){
							ParkwellPayBillVo pvBillVo=serverice.addCarParkOutBillLock(cc);
							/*ParkwellPayBillVo pvBillVo=carParkOutService.queryGenerateVirtualBill(cc);*/
							//满足流水，自动开闸
							serverice.savePayBillLock(pvBillVo);
						}
					}
				}
				
				result.setResult(CommonContans.STRUTS_SUCCESS);
			} catch (Exception e)
			{
				log.error(e.getMessage(), e);
				result.setResult(CommonContans.STRUTS_ERROR);
				result.setErrorCode(e.getMessage().length() > 32 ? CommonContans.COMMON_ERROR_CODE
						: e.getMessage());
				result.setErrorMsg(e.getMessage().length() > 32 ? I18nUtil
						.getErroryCodeInfo(CommonContans.COMMON_ERROR_CODE)
						: I18nUtil.getErroryCodeInfo(e.getMessage()));
			}
		}
		return result;
	}
	
}
